package org.lionsoul.websnail.downloader.webdriver;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;

/**
 * WebDriver wrapper
 *
 * @author yangjian
 **/
public class SnailWebDriver
{

    public static final int RUNNING = 1; // 运行中
    public static final int IDLE = 2; // 空闲
    private int state = IDLE;
    private final WebDriver webDriver;
    // 等待页面加载完成的条件
    private ExpectedCondition<WebElement> condition;
    // 要获取的页面元素选择器
    private By selector;

    public SnailWebDriver(WebDriver driver, ExpectedCondition<WebElement> condition, By selector)
    {
        assert driver != null;
        this.webDriver = driver;
        this.condition = condition;
        this.selector = selector;
    }

    public SnailWebDriver(WebDriver driver)
    {
        this(driver, null, null);
    }

    public synchronized int getState()
    {
        return state;
    }

    public synchronized void setState(int state)
    {
        this.state = state;
    }

    public WebDriver getWebDriver()
    {
        return webDriver;
    }

    public ExpectedCondition<WebElement> getCondition()
    {
        return condition;
    }

    public void setCondition(ExpectedCondition<WebElement> condition)
    {
        this.condition = condition;
    }

    public By getSelector()
    {
        return selector;
    }

    public void setSelector(By selector)
    {
        this.selector = selector;
    }
}
